<template>
  <!-- 汇付交易流水 -->
  <el-dialog title="交易流水" :visible.sync="dialogVisible" :close-on-click-modal="false" width="1300px" append-to-body>
    <el-form class="search-form-new" :model="queryParams" ref="queryForm" :inline="true">
      <div class="search-box">

        <el-form-item label="支付时间" prop="acctDate">
          <el-date-picker v-model="timer" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" placeholder="请选择日期" value-format="yyyy-MM-dd" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="业务订单号" prop="no">
          <el-input v-model="queryParams.no" placeholder="业务订单号" clearable size="small" />
        </el-form-item>
        <el-form-item label="商品编号" prop="goodsId">
          <el-input v-model="queryParams.goodsId" placeholder="商品编号" clearable size="small" />
        </el-form-item>
        <el-form-item label="结算状态" prop="yanshiState">
          <el-select clearable v-model="queryParams.yanshiState" placeholder="请选择结算状态"  >
            <el-option  label="未结算" :value="2" />
            <el-option  label="已结算" :value="3" />
          </el-select>
        </el-form-item>

        <el-form-item class="btns">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <!-- <el-button icon="el-icon-refresh" @click="resetQuery">重置/刷新</el-button> -->
        </el-form-item>
      </div>
    </el-form>
    <div class="table_box">
      <div class="total_box">
        <b>支付金额合计：<span style="font-size: 20px;">{{ hejiObj.payTotalMoneySum }}</span></b>
        <b>结算金额合计：<span style="font-size:20px;color:red ;">{{ hejiObj.daoshouAmountSum }}</span></b>
      </div>
      <el-table :data="tableData.records" style="width: 100%" stripe border>
        <!-- <el-table-column prop="createTime" label="创建时间" width="165"></el-table-column> -->
        <el-table-column prop="payEndTime" label="支付时间" width="165"></el-table-column>
        <el-table-column prop="goodsId" label="商品编号" width="100"></el-table-column>
        <el-table-column prop="accountNumber" label="游戏账号" width="100"></el-table-column>
        <el-table-column prop="no" label="订单编号" width="210"></el-table-column>
        <el-table-column prop="" label="支付方式" width="100">
          <template slot-scope="scope">
            <span >{{ commonMaps.payWayMap[scope.row.payWay] }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="payTotalMoney" label="支付金额" width="100"></el-table-column>
        <el-table-column prop="zhifuFee" label="支付手续费" width="100"></el-table-column>
        <el-table-column prop="" label="技术服务费" width="100">
          <template slot-scope="scope">
            <span style="color: #666;">{{ scope.row.serviceFee }}</span>
            <!-- <div v-if="scope.row.remark&&getRemark(scope.row.remark).jiesuan">
              <div>
                <span style="color: #666;font-size: 16px;">{{ getRemark(scope.row.remark).fuwufei }}</span>
              </div>
            </div> -->
          </template>
        </el-table-column>
        <el-table-column prop="daoshouAmount" label="结算金额" width="100">
          <template slot-scope="scope">
            <b style="color: red;font-size: 18px;">{{ scope.row.daoshouAmount }}</b>
            <!-- <div v-if="scope.row.remark&&getRemark(scope.row.remark).jiesuan">
              <div>
                <b style="color: red;font-size: 18px;">{{ getRemark(scope.row.remark).jiesuan }}</b>
              </div>
            </div> -->
          </template>
        </el-table-column>
        <!-- <el-table-column prop="trans_amt" label="备注" >
          <template slot-scope="scope">
            <div v-if="scope.row.remark&&getRemark(scope.row.remark).jiesuan">
              <div>
                <b>结算金额 <span>{{ getRemark(scope.row.remark).jiesuan }}</span></b>；
                <b>服务费 <span>{{ getRemark(scope.row.remark).fuwufei }} </span></b><span>(包含技术服务费和支付渠道手续费)</span>
              </div>
            </div>
          </template>
        </el-table-column> -->
        <el-table-column prop="orderState" label="支付状态" width="100">
          <template slot-scope="scope">
            <el-tag :type="commonMaps.payOrderStateMap[scope.row.orderState].type">{{ commonMaps.payOrderStateMap[scope.row.orderState].name
            }}</el-tag>

          </template>
        </el-table-column>
        <el-table-column prop="yanshiState" label="结算状态" >
          <template slot-scope="scope">
            <el-tag :type="commonMaps.yanshiStateMap[scope.row.yanshiState].type">{{ commonMaps.yanshiStateMap[scope.row.yanshiState].name
            }}</el-tag>

          </template>
        </el-table-column>

      </el-table>

      <pagination :layout="'total, prev,pager,next'" :total="tableData.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    </div>
  </el-dialog>

</template>
<script>
import { mapGetters } from "vuex";
import payApi from "@/api/financeCenter/pay";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      timer: [],
      tableData: {
        records: [],
        total: 0,
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginDate: "",
        endDate: "",
        isHuifu: "2",
        orderState: 2,
      },
      // 合计金额
      hejiObj:{}
    };
  },
  created() {},
  computed: {
  
    ...mapGetters(["userInfo"]),
    // getRemark() {
    //   return (str) => {
    //     let obj = {};
    //     let result = {};
    //     if (str) obj = JSON.parse(str);
    //     if (obj.acct_split_bunch) {
    //       const tempArr = JSON.parse(obj.acct_split_bunch).acct_infos;
    //       if (tempArr && tempArr.length) {
    //         result.fuwufei = 0;
    //         result.jiesuan = 0;
    //         tempArr.forEach((r) => {
    //           const amt = Number(r.div_amt);
    //           if (amt > result.jiesuan) {
    //             result.jiesuan = amt;
    //           }
    //           if (amt < result.fuwufei || result.fuwufei == 0) {
    //             result.fuwufei = amt;
    //           }
    //         });
    //         result.jiesuan = result.jiesuan - 1;
    //         result.fuwufei = result.fuwufei + 1;
    //       }
    //     }
    //     return result;
    //   };
    // },
  },
  methods: {
    open() {
      const now = new Date();
      const year = now.getFullYear();
      const month = now.getMonth() + 1;
      const day = now.getDate();
      const nowDate = `${year}-${month > 9 ? month : "0" + month}-${
        day > 9 ? day : "0" + day
      }`;
      this.timer = [nowDate,nowDate]

      
      this.dialogVisible = true;
      this.getList();
    },
    // 获取列表
    getList() {
      if (this.userInfo?.tenantId) {
        // queryParams 请求列表
        this.loading = true;
        if (this.timer && this.timer.length) {
          this.queryParams.payEndTimeStart = this.timer[0] + " 00:00:00"
          this.queryParams.payEndTimeEnd = this.timer[1] + ' 23:59:59'
        } else {
          this.queryParams.payEndTimeStart = ''
          this.queryParams.payEndTimeEnd = ''
        }
        this.queryParams.tenantId = this.userInfo?.tenantId;
        payApi.getPayRecords(this.queryParams).then((res) => {
          this.loading = false;
          this.tableData.records = [];
          if (res.code == 200) {
            this.hejiObj = {...res.params}
            this.tableData.records = res.rows;
            this.tableData.total = res.total;
          }
        });
      } else {
        return;
      }
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.timer = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        beginDate: "",
        endDate: "",
      };
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .search-box {
    // width: 790px;
    // margin: 0 auto;
  }
}
::v-deep .el-date-editor {
  .el-input__inner {
    padding-left: 30px;
  }
}
.total_box{
  margin: 5px 0 15px;
  b{
    margin-right: 20px;
    line-height: 20px;
  }
}
</style>
